import os
import time

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By


class Loginform:
      def __init__(self):
       self.driver=webdriver.Chrome()
       file= "file:///" + os.path.abspath("html") +"/注册实例.html"
       self.driver.get(file)


      #第一张表
      def registerA(self):
        #注册用户.
        time.sleep(3)
        self.driver.find_element(By.ID,'user').send_keys('JDJDJ')
        #写入密码
        time.sleep(3)
        self.driver.find_element(By.ID,"password").send_keys('123456')
        #写入电话
        time.sleep(3)
        self.driver.find_element(By.ID,'tel').send_keys('13000000000')
        #写入邮箱
        time.sleep(3)
        self.driver.find_element(By.ID,'email').send_keys('432219915@mail.com')
        #点击注册用户
        time.sleep(3)
        zc=self.driver.find_element(By.TAG_NAME,'button').click()
        time.sleep(3)


      #第二张
      def registerB(self):
          #定位表a
          frame1=self.driver.find_element(By.ID,'idframe1')
          #切换到指定的iframe
          self.driver.switch_to.frame(frame1)
          # 注册用户.
          time.sleep(3)
          self.driver.find_element(By.ID, 'userA').send_keys('AJDJDJ')
          # 写入密码
          time.sleep(3)
          self.driver.find_element(By.ID, "passwordA").send_keys('1234561')
          # 写入电话
          time.sleep(3)
          self.driver.find_element(By.ID, 'telA').send_keys('13000000001')
          # 写入邮箱
          time.sleep(3)
          self.driver.find_element(By.ID, 'emailA').send_keys('4322199151@mail.com')
          # 点击注册用户
          time.sleep(3)
          zc1 = self.driver.find_element(By.TAG_NAME,'button').click()
          time.sleep(3)



      #第三张
      def registerC(self):
          # 返回主页面
          self.driver.switch_to.default_content()
          # 定位第3张表
          frame2 = self.driver.find_element(By.NAME, 'myframe2')
          #切换到表b
          self.driver.switch_to.frame(frame2)
          # 注册用户.
          time.sleep(3)
          self.driver.find_element(By.ID, 'userB').send_keys('BJDJDJ')
          # 写入密码
          time.sleep(3)
          self.driver.find_element(By.ID, "passwordB").send_keys('1234562')
          # 写入电话
          time.sleep(3)
          self.driver.find_element(By.ID, 'telB').send_keys('13000000002')
          # 写入邮箱
          time.sleep(3)
          self.driver.find_element(By.ID, 'emailB').send_keys('4322199152@mail.com')
          # 点击注册用户
          time.sleep(3)
          ZC2=self.driver.find_element(By.TAG_NAME,'button').click()
          time.sleep(3)




      def quit(self):
       time.sleep(3)
       self.driver.quit()


if __name__ == '__main__':
    su=Loginform()
    su.registerA()
    su.registerB()
    su.registerC()
    su.quit()
